import datetime
from typing import Optional

from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel

from module_admin.annotation.pydantic_annotation import as_query


class TradeModel(BaseModel):
    """
    总交易流水表对应pydantic模型
    """

    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    id: Optional[int] = Field(default=None, description='总交易流水id')
    name: Optional[str] = Field(default=None, description='策略名称')
    trade_id: Optional[int] = Field(default=None, description='策略交易流水id')
    date: Optional[datetime.date] = Field(default=None, description='交易日期')
    time: Optional[datetime.time] = Field(default=None, description='交易时间')
    price: Optional[float] = Field(default=None, description='交易价格')
    direction: Optional[str] = Field(default=None, description='交易方向')
    offset: Optional[str] = Field(default=None, description='开平标志')
    volume: Optional[int] = Field(default=None, description='交易量')
    pos: Optional[int] = Field(default=None, description='交易后持仓')


@as_query
class TradeQueryModel(TradeModel):
    """
    成交记录管理不分页查询模型
    """

    begin_time: Optional[str] = Field(default=None, description='开始日期')
    end_time: Optional[str] = Field(default=None, description='结束日期')


@as_query
class TradePageQueryModel(TradeQueryModel):
    """
    成交记录管理分页查询模型
    """

    page_num: int = Field(default=1, description='当前页码')
    page_size: int = Field(default=10, description='每页记录数')


class DeleteTradeModel(BaseModel):
    """
    删除成交记录模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

    trade_ids: str = Field(description='需要删除的参数主键')
